package ar.edu.itba.it.paw.web.base;

import org.apache.wicket.markup.html.link.Link;


import ar.edu.itba.it.paw.web.HomePage;
import ar.edu.itba.it.paw.web.MercadoLibreSession;


public abstract class SecuredPage extends BasePage {

	public SecuredPage() {
		MercadoLibreSession session = getMercadoLibreSession();
		if (!session.isSignedIn()) {
			redirectToInterceptPage(new HomePage());
			//throw new RestartResponseException(LoginPage.class);
		}

		add(new Link<Void>("logout") {
			@Override
			public void onClick() {
				getMercadoLibreSession().signOut();
				setResponsePage(getApplication().getHomePage());
			}
		});
	}

	protected MercadoLibreSession getMercadoLibreSession() {
		return (MercadoLibreSession) getSession();
	}
}